package io.renren.controller;

import com.baomidou.mybatisplus.extension.api.R;
import io.renren.annotation.LoginUser;
import io.renren.common.constant.Constant;
import io.renren.common.exception.RRException;
import io.renren.common.page.PageData;
import io.renren.common.utils.ExcelUtil;
import io.renren.common.utils.Result;
import io.renren.common.validator.AssertUtils;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.DefaultGroup;
import io.renren.common.validator.group.UpdateGroup;
import io.renren.dto.FoodDTO;
import io.renren.entity.UserEntity;
import io.renren.service.FoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


/**
 * 食材表（辅材共用）
 *
 * @author 翟文闯 619556390@QQ.com
 * @since 1.0.0 2019-11-22
 */
@RestController
@RequestMapping("api/food")
@Api(tags="食材采购")
public class FoodController {
    @GetMapping("page")
    @ApiOperation("食材列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
            @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
            @ApiImplicitParam(name = "foodName", value = "名称", paramType = "query", required = false,dataType="String") ,
            @ApiImplicitParam(name = "type", value = "类型（1、食材 2、辅材 ）", paramType = "query", required = true,dataType="String") ,
            @ApiImplicitParam(name = "variety", value = "种类（1、肉蛋熟食(油)2、海鲜水产(米)3、新鲜素材(调味品)4、粮油速食(其他)）", paramType = "query", required = true,dataType="String") ,
            @ApiImplicitParam(name = Constant.ORDER, value = "排序方式，可选值(asc、desc)", paramType = "query", dataType="String")
    })
    public Result<PageData<FoodDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
        PageData<FoodDTO> page = foodService.page(params);

        return new Result<PageData<FoodDTO>>().ok(page);
    }

    @Autowired
    private FoodService foodService;

    @GetMapping("/supplierFoodId")
    @ApiOperation("供应商提供的产品")
    public Result<List<FoodDTO>> supplierFoodId(Long supplierFoodId,String variety,String foodName,String type,int sign,Long orderId, @LoginUser UserEntity entity) { //通过供应商id和商品的种类获取商品信息
        List<FoodDTO> data = foodService.supplierFoodId(supplierFoodId,variety,foodName,type,sign,orderId,entity);
        System.out.println(data);
        return new Result<List<FoodDTO>>().ok(data);
    }
    @GetMapping("/getSupplierName")
    @ApiOperation("根据产品名查询供应商")
    public Result<Map> getSupplierName(String foodName,int sign, Long orderId,@LoginUser UserEntity entity) { //通过供应商id和商品的种类获取商品信息
        Map data = foodService.getSupplierName(foodName,sign,orderId,entity);
        return new Result<Map>().ok(data);
    }
  /*  *
     * 辅材详情表查询
     * @param variety
     * @param name
     * @return
     */
    @GetMapping("/selectCoolerFoodId")
    @ApiOperation("辅材详情表查询")
    public Result<List<FoodDTO>> selectCoolerFoodId(String name,String variety,int sign,Long orderId, @LoginUser UserEntity entity) { //通过供应商id和商品的种类获取商品信息
        List<FoodDTO> data = foodService.selectCoolerFoodId(name,variety,sign,orderId,entity);
        return new Result<List<FoodDTO>>().ok(data);
    }
}